package com.czkevin.cif.crafting;

import com.czkevin.cif.crafting.recipe.CIFRecipe;
import org.bukkit.inventory.ItemStack;

import java.util.*;

public final class RecipeRegister {

    private static final Set<String> registered = new HashSet<>();
    private static final List<CIFRecipe> recipes = new LinkedList<>();

    private static boolean inited = false;
    public static void init() {
        if (inited) return;
        inited = true;
        // ...
    }

    public static void register(CIFRecipe recipe) {
        if(!registered.add(recipe.getName())) throw new IllegalArgumentException(String.format("Recipe [%s] registered! ", recipe.getName()));
        recipes.add(recipe);
    }

    public static RecipeMatch match(ItemStack[][] matrix) {
        for(CIFRecipe r : recipes) {
            RecipeMatch match = r.matches(matrix);
            if(match != null) return match;
        }
        return null;
    }

    public static Iterator<CIFRecipe> iterator() {
        return recipes.iterator();
    }

}
